package com.zysc.processflow.common.maputil;

public class Vector2D {
    public double x;
    public double y;

    public Vector2D() {
        x = 0;
        y = 0;
    }

    public Vector2D(double _x, double _y) {
        x = _x;
        y = _y;
    }

    //获取弧度
    public double getRadian() {
        return Math.atan2(y, x);
    }

    //获取角度
    public double getAngle() {
        return getRadian() / Math.PI * 180;
    }

    public Vector2D clone() {
        return new Vector2D(x, y);
    }

    public double getLength() {
        return Math.sqrt(getLengthSQ());
    }

    public double getLengthSQ() {
        return x * x + y * y;
    }

    //2个向量的数量积(点积)
    public double dotProduct(Vector2D v) {
        return x * v.x + y * v.y;
    }

    //2个向量的向量积( )
    public double crossProduct(Vector2D v) {
        return x * v.y - y * v.x;
    }
}
